import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'payment_service_interface.dart';

/// 模拟器的支付宝支付服务实现（纯Dart，无原生依赖）
class AlipayServiceMock implements PaymentServiceInterface {
  
  @override
  Future<void> init() async {
    debugPrint('✅ 模拟器环境，使用Mock支付服务');
  }

  @override
  Future<bool> isInstalled() async {
    debugPrint('🎭 模拟器：模拟支付宝已安装');
    return true;
  }

  @override
  Future<Map<String, dynamic>?> pay(String orderString) async {
    debugPrint('🎭 模拟器：模拟支付流程');
    
    // 显示模拟支付选择对话框
    return await Get.dialog<Map<String, dynamic>>(
      AlertDialog(
        title: Row(
          children: [
            Icon(Icons.payment, color: Colors.blue),
            SizedBox(width: 8),
            Text('模拟支付'),
          ],
        ),
        content: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              padding: EdgeInsets.all(12),
              decoration: BoxDecoration(
                color: Colors.orange.withOpacity(0.1),
                borderRadius: BorderRadius.circular(8),
                border: Border.all(color: Colors.orange.withOpacity(0.3)),
              ),
              child: Row(
                children: [
                  Icon(Icons.info_outline, color: Colors.orange, size: 20),
                  SizedBox(width: 8),
                  Expanded(
                    child: Text(
                      'iOS模拟器环境，选择模拟支付结果：',
                      style: TextStyle(fontSize: 14, color: Colors.orange[800]),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(height: 12),
            Container(
              padding: EdgeInsets.all(8),
              decoration: BoxDecoration(
                color: Colors.grey[50],
                borderRadius: BorderRadius.circular(6),
              ),
              child: Text(
                '订单信息：${orderString.length > 80 ? orderString.substring(0, 80) + '...' : orderString}', 
                style: TextStyle(fontSize: 11, color: Colors.grey[600]),
              ),
            ),
          ],
        ),
        actions: [
          TextButton(
            onPressed: () => Get.back(result: {
              'resultStatus': '6001',
              'result': '用户取消',
            }),
            child: Text('取消支付', style: TextStyle(color: Colors.grey)),
          ),
          TextButton(
            onPressed: () => Get.back(result: {
              'resultStatus': '4000', 
              'result': '支付失败',
            }),
            child: Text('支付失败', style: TextStyle(color: Colors.red)),
          ),
          ElevatedButton(
            style: ElevatedButton.styleFrom(
              backgroundColor: Colors.green,
              foregroundColor: Colors.white,
            ),
            onPressed: () => Get.back(result: {
              'resultStatus': '9000',
              'result': '支付成功',
              'memo': '模拟器测试支付',
              'resultInfo': 'success',
            }),
            child: Text('支付成功'),
          ),
        ],
      ),
      barrierDismissible: false,
    );
  }
}

